package com.sz.mes.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diboot.core.vo.JsonResult;
import com.sz.mes.entity.TaskTemplate;
import com.sz.mes.mapper.TaskTemplateMapper;
import com.sz.mes.service.TaskTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 任务模板相关Service实现
* @author hem
* @version 1.0
* @date 2024-01-26
 * Copyright © szhs
*/
@Service
@Slf4j
public class TaskTemplateServiceImpl extends BaseCustomServiceImpl<TaskTemplateMapper, TaskTemplate> implements TaskTemplateService {

    private final TaskTemplateMapper taskTemplateMapper;

    public TaskTemplateServiceImpl(TaskTemplateMapper taskTemplateMapper) {
        this.taskTemplateMapper = taskTemplateMapper;
    }

    @Override
    public JsonResult findNewestTemplate(String type, String version) {
        QueryWrapper<TaskTemplate> tqw = new QueryWrapper<>();
//        tqw.orderByDesc("create_time")
//                .last("limit 1");
        tqw.eq("version", version);
        tqw.eq("type", type);
        List<TaskTemplate> taskTemplates = taskTemplateMapper.selectList(tqw);
        return JsonResult.OK(taskTemplates);
    }
}
